/*
 * UnixCommand.cpp
 *
 *  Created on: Aug 11, 2010
 *      Author: bubuntux
 */

#include "UnixCommand.h"

string UnixCommand::exec(const char* cmd) {
	FILE* pipe = popen(cmd, "r");
	if (!pipe)
		return "ERROR";
	char buffer[128];
	string result = "";
	while (!feof(pipe)) {
		if (fgets(buffer, 128, pipe) != NULL)
			result += buffer;
	}
	pclose(pipe);
	return result;
}

int UnixCommand::getBiggestDevice() {
	int device = -1;
	sscanf(
			exec("lsusb | awk '{print $4}' | sort -r | head -n 1").substr(0, 3).c_str(),
			"%d", &device);
	return device;
}
